<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:replace="_fragments::head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link rel="stylesheet" href="../../static/css/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">

    <title>博客管理</title>
</head>


<body>

<!--导航-->
<nav th:replace="admin/_fragments::menu(1)" class="ui inverted attached segment"></nav>


<!--二级导航-->
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a th:href="@{/admin/blog/save}" href="blog-input.html" class="item">编辑</a>
            <a th:href="@{/admin/blog}" href="blog.html" class="teal active item">列表</a>
        </div>
    </div>
</div>


<!--中间内容-->
<div class="m-padded-tb-big m-container-small">
    <div class="ui container">
        <!--搜索框表单-->
        <div class="ui secondary segment form">
            <!--隐藏域:页码-->
            <input type="hidden" name="page">
            <!--筛选栏-->
            <div class="inline fields">
                <!--标题输入框-->
                <div class="field">
                    <input type="text" name="title" placeholder="标题">
                </div>
                <!--分类下拉框-->
                <div class="field">
                    <div class="ui labeled action input">
                        <div class="ui type-clear search selection dropdown">
                            <!--隐藏域：分类 ID-->
                            <input type="hidden" name="typeId">
                            <div class="default text">分类</div>
                            <i class="dropdown icon"></i>
                            <div class="menu">
                                <div class="item" data-value="1"
                                     th:each="type : ${typeList}"
                                     th:data-value="${type.id}"
                                     th:text="${type.name}">
                                    错误日志
                                </div>
                                <!--/*-->
                                <div class="item" data-value="2">开发者手册</div>
                                <!--*/-->
                            </div>
                        </div>
                    </div>
                </div>
                <!--是否推荐选择框-->
                <div class="field">
                    <div class="ui checkbox">
                        <input type="checkbox" id="recommend" name="recommend">
                        <label for="recommend">推荐</label>
                    </div>
                </div>
                <!--搜索按钮-->
                <div class="field">
                    <button type="button" id="search-btn" class="ui mini teal basic button">
                        <i class="search icon"></i>搜索
                    </button>
                </div>
            </div>
        </div>
        <!--博客列表-->
        <div id="table-container">
            <!--操作成功消息提示-->
            <!--/*/
            <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
                <i class="close icon"></i>
                <div class="header">提示：</div>
                <p th:text="${message}">恭喜，操作成功！</p>
            </div>
            /*/-->
            <!--博客列表-->
            <table class="ui compact teal table" th:fragment="blogList">
                <thead>
                <tr>
                    <th>行号</th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>推荐</th>
                    <th>状态</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <tr th:each="blog,iterStat : ${page.content}">
                    <td th:text="${iterStat.count}">1</td>
                    <td th:text="${blog.title}">刻意练习清单</td>
                    <td th:text="${blog.type.name}">认知升级</td>
                    <td th:text="${blog.recommend} ? '是' : '否'">是</td>
                    <td th:text="${blog.published} ? '发布' : '草稿'">草稿</td>
                    <td th:text="${blog.updateTime}">2017-10-02 09:45</td>
                    <td>
                        <a href="#" th:href="@{/admin/blog/update/{id}(id=${blog.id})}"
                           class="ui mini teal basic button">
                            编辑
                        </a>
                        <a href="#" th:href="@{/admin/blog/delete/{id}(id=${blog.id})}"
                           class="ui mini red basic button">
                            删除
                        </a>
                    </td>
                </tr>
                </tbody>
                <tfoot>
                <tr>
                    <th colspan="7">
                        <!--翻页按钮-->
                        <div class="ui mini pagination menu" th:if="${page.totalPages}>1">
                            <a class="item" onclick="page(this)" th:unless="${page.first}"
                               th:attr="data-page=${page.number}-1">
                                上一页
                            </a>
                            <a class="item" onclick="page(this)" th:unless="${page.last}"
                               th:attr="data-page=${page.number}+1">
                                下一页
                            </a>
                        </div>
                        <!--新增按钮-->
                        <a th:href="@{/admin/blog/save}" href="blog-input.html"
                           class="ui mini right floated teal basic button">
                            新增
                        </a>
                    </th>
                </tr>
                </tfoot>
            </table>
        </div>
    </div>
</div>


<!--/*/<th:block th:replace="admin/_fragments::script">/*/-->
<script src="../../static/js/jquery.min.js"></script>
<script src="../../static/js/semantic.min.js"></script>
<!--/*/</th:block>/*/-->

<script>
    /*页面加载初始化函数*/
    $(function () {
        $('.type-clear').dropdown({
            clearable: true
        });
    });


    function page(obj) {
        $("[name='page']").val($(obj).data("page"));
        loadData();
    }

    function loadData() {
        $("#table-container").load(/*[[@{/admin/blog/search}]]*/"/admin/blog/search", {
            title: $("[name='title']").val(),
            typeId: $("[name='typeId']").val(),
            recommend: $("[name='recommend']").prop('checked'),
            page: $("[name='page']").val()
        });
    }

    $("#search-btn").on('click', function () {
        $('[name="page"]').val(0);
        loadData();
    });
</script>

</body>
</html>